﻿using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class ReporteadorAnimales : System.Web.UI.Page
{ 
    private string Reporte;
    private string rutaReporte;
    private string formula = "";
    protected void Page_Load(object sender, EventArgs e)
    {
          
        if (!Page.IsPostBack)
        {
            rutaReporte = ConfigurationManager.AppSettings.Get("rutaReportes");
            ReportDocument myReport = new ReportDocument();
            myReport.Load(Server.MapPath(rutaReporte + (string)Session["nombreReporte"]));
            //tambien se puede usar rutaReporte = HttpContext.Current.Server.MapPath("~/Reportes/");

           
            Tables myTables = myReport.Database.Tables;
            ConnectionInfo myConnectionInfo = new ConnectionInfo();
            foreach (CrystalDecisions.CrystalReports.Engine.Table myTable in myTables)
            {
                TableLogOnInfo myTableLogonInfo = myTable.LogOnInfo;
                myConnectionInfo.ServerName = "localhost"; //Your server
                // <SQL servername>
                myConnectionInfo.DatabaseName = "veterinariaPAW"; //Leave DB Blank
                //// leave database name blank
                myConnectionInfo.UserID = "sa"; //Your User
                // username
                myConnectionInfo.Password = "123456a!"; //Your Users Password
                //password

                myTableLogonInfo.ConnectionInfo = myConnectionInfo;
                myTable.ApplyLogOnInfo(myTableLogonInfo);
            }


            //Reporte = myReport;
            CrystalReportViewer1.EnableDatabaseLogonPrompt = false;
            CrystalReportViewer1.ReportSource = myReport;
            CrystalReportViewer1.DataBind();
            CrystalReportViewer1.RefreshReport();
        }
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Redirect((string)Session["URL"]);
    }
}